package com.dundun.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dundun.domain.Internship;
import com.dundun.mapper.InternshipMapper;
import com.dundun.service.InternshipService;
import com.dundun.service.JobRelationshipService;
import com.dundun.domain.JobRelationship;
import com.dundun.mapper.JobRelationshipMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author wq
* @description 针对表【job_relationship】的数据库操作Service实现
* @createDate 2022-11-19 10:02:05
*/
@Service("jobRelationshipService")
public class JobRelationshipServiceImpl extends ServiceImpl<JobRelationshipMapper, JobRelationship>
    implements JobRelationshipService{
    @Autowired
    private JobRelationshipMapper jobRelationshipMapper;
    @Autowired
    private InternshipMapper internshipMapper;

    @Override
    public List<Map<String, Object>> GetResumeStatusByPage(int userId,int pageNum,int pageSize) {
        //通过Page对象确定页数和页面大小
        Page<JobRelationship> page = new Page<>(pageNum,pageSize);
        //构建条件查询器
        QueryWrapper<JobRelationship> qw = new QueryWrapper<>();
        qw.eq("user_id",userId);
        //分页查询
        jobRelationshipMapper.selectPage(page,qw);
        //封装结果对象
        List<JobRelationship> jobRelationShipList = page.getRecords();
        List<Map<String,Object>> maps = new ArrayList<>();
        for (JobRelationship jobRelationship : jobRelationShipList) {
            Internship internship = internshipMapper.selectById(jobRelationship.getInternshipId());
            Map<String,Object> map = new HashMap<>();
            map.put("jobStatus",jobRelationship);
            map.put("internship",internship);
            maps.add(map);
        }
        //返回结果对象
        return maps;
    }
}




